﻿using System;
using System.Web;
using System.Web.Services;
using System.ComponentModel;
using System.Reflection;
using System.Collections.Generic;

using SBPweb.Services.Base;
using SBPweb.Services.Crawlers.Base;

namespace SBPweb.Services.Crawlers.IMDB
{

    [WebService(
        Name = "SBPweb Crawler service - IMDB",
        Namespace = "http://services.sbpweb.hu/crawlers/IMDB",
        Description = "services.sbpweb.hu/crawlers/IMDB")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class Service : ServiceBase
    {

        #region Private fields

        private Uri pBaseUri;

        #endregion

        #region Constructor logic

        public Service()
        {
            pBaseUri = new Uri(Properties.Settings.Default.BaseUri);
        }

        public Service(Uri baseUri)
        {
            pBaseUri = baseUri;
        }

        #endregion

        #region Methods
        /*
        [WebMethod(true)]
        public string Search(string phrase)
        {
            Client client = new Client(pBaseUri);
            Uri uri = new Uri(string.Format("{0}find?q={1}", pBaseUri, phrase));
            string content = client.ParseRequest(uri);
            return content;
        }
        */
        [WebMethod(true)]
        public SBPweb.Services.Crawlers.Movies.Movies.TitleRow RequestTitleById(string titleId)
        {
            Uri uri = new Uri(string.Format("{0}title/{1}/", pBaseUri, titleId));
            Client client = new Client(uri);
            string content = client.ParseRequest(uri);
            SBPweb.Services.Crawlers.Movies.Movies.TitleDataTable table = new SBPweb.Services.Crawlers.Movies.Movies.TitleDataTable();
            SBPweb.Services.Crawlers.Movies.Movies.TitleRow row = table.NewTitleRow();
            row.Title = "blabla";
            row.Id = titleId;
            row.ReleaseDate = DateTime.Now;
            row.DirectorId = 0;
            return row;
        }
        /*
        [WebMethod(true)]
        public Data.TitleRow RequestTitleById(string titleId)
        {
            Uri uri = new Uri(string.Format("{0}title/{1}/", pBaseUri, titleId));
            Client client = new Client(uri);
            string content = client.ParseRequest(uri);
            Data.TitleRow row = new Data.TitleRow(content);
            row.Title = "blabla";
            row.Id = titleId;
            row.ReleaseDate = DateTime.Now;
            row.DirectorId = 0;
            return row;
        }
        */
        #endregion

    }

}